package net.jsoft.pms.job.iface;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import net.jsoft.platform.core.entity.core.param.CoreParam;
import net.jsoft.platform.core.repository.core.param.ParamsRepository;
import net.jsoft.platform.core.util.platform.PlatformUtils;
import net.jsoft.platform.core.util.spring.SpringUtil;
import net.jsoft.platform.schedule.job.BaseJob;
import net.jsoft.pms.entity.ywfwqd.YwfwqdEntity;
import net.jsoft.pms.mapper.scs.ServicesListMapper;
import net.jsoft.pms.repository.ywfwqd.YwfwqdRepository;
import net.jsoft.pms.vo.scs.Service;

@Component
public class GetInterfaceJob extends BaseJob
{
    @Autowired
    private ServicesListMapper mapper;

    @Autowired
    private ParamsRepository repository;

    @Autowired
    private YwfwqdRepository ywqd;

    @Override
    public void doExecute(JobExecutionContext context) throws JobExecutionException
    //    public void execute()
    {
        repository = (ParamsRepository) SpringUtil.getBean("paramsRepository");
        ywqd = (YwfwqdRepository) SpringUtil.getBean("ywfwqdRepository");
        mapper = (ServicesListMapper) SpringUtil.getBean("servicesListMapper");

        CoreParam date = repository.selectParams("scsdate");
        List<Service> sc = null;
        String queryDate = null;
        List<YwfwqdEntity> list = new ArrayList<YwfwqdEntity>();
        YwfwqdEntity ywfwqd = null;
        try
        {
            queryDate = PlatformUtils.formateDate(PlatformUtils.getSysDate(), "yyyy-MM-dd HH:mm:ss");
        }
        catch (ParseException e)
        {
            e.printStackTrace();
        }
        if (date == null)
        {
            sc = mapper.findAll();
            date = new CoreParam();
            date.setName("scsdate");
            date.setValue(queryDate);
        }
        else
        {
            sc = mapper.findFromDate(date.getValue());
            date.setValue(queryDate);
        }

        for (Service s : sc)
        {
            ywfwqd = ywqd.findOneByYwfwid(s.getYwfwid());
            if (ywfwqd == null)
            {
                ywfwqd = new YwfwqdEntity();
            }
            ywfwqd.setCzlx(s.getCzlx());
            ywfwqd.setDwfbzt(s.getDwfbzt());
            ywfwqd.setFwbbh(s.getFwbbh());
            ywfwqd.setFwfbrq(s.getFwfbrq());
            ywfwqd.setFwljms(s.getFwljms());
            ywfwqd.setFwlx(s.getFwlx());
            ywfwqd.setGdslx(s.getGdslx());
            ywfwqd.setLrr_dm(s.getLrr_dm());
            ywfwqd.setLrrq(s.getLrrq());
            ywfwqd.setQyfwyfwid(s.getQyfwyfwid());
            ywfwqd.setRequestbean(s.getRequestBean());
            ywfwqd.setRequestxsd(s.getRequestxsd());
            ywfwqd.setResponsebean(s.getResponseBean());
            ywfwqd.setResponsexsd(s.getResponseBean());
            ywfwqd.setSccs(s.getSccs());
            ywfwqd.setSclm(s.getSclm());
            ywfwqd.setSrcs(s.getSrcs());
            ywfwqd.setSszb(s.getSszb());
            ywfwqd.setXgr_dm(s.getXgr_dm());
            ywfwqd.setXgrq(s.getXgrq());
            ywfwqd.setYwfwid(s.getYwfwid());
            ywfwqd.setYwfwmc(s.getYwfwmc());
            ywfwqd.setYwfwxh(s.getYwfwxh());
            ywfwqd.setYwy(s.getYwy());
            ywfwqd.setZxt(s.getZxt());
            list.add(ywfwqd);
        }
        ywqd.save(list);
        repository.save(date);
    }
}
